<?php
/**
 * Triple-B micro Framework for PHP5
 * Copyright (C) 2013  PT. Triple-B Shamany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @resource
 * @singleton
 */
final class Test {
    public function memory() {
        $u = array("b", "kb", "mb", "gb");
        $b = memory_get_usage();
        return sprintf("<pre>memory_get_usage: %s %s</pre>", round($b / pow(1024, $v = floor(log($b, 1024))), 2), $u[$v]);
    }

    /**
     * fungsi hitung dengan annotation. jika @argument dihapus, framework tidak
     * akan menangani parameter yang diterima.
     *
     * note: argument dengan tipe digit memiliki attribute minvalue/maxvalue
     *
     * @argument     {"type": "digit", "minv": 1, "maxv": 10}
     * @argument     {"type": "digit", "minv": 2, "maxv": 10}
     */
    public function GET($a, $b) {
        $c = "<pre>";
        $c.= sprintf('hitung($a(%d), $b(%d)): $a + $b = %d  # coba dengan parameter selain digit!', $a, $b, $a + $b);
        $c.= "\n\n";
        $c.= "pada framework seperti: CI, Yii, Zend, dkk..\n";
        $c.= "tugas validasi diserahkan kepada developer, atau biasanya disediakan fungsi2 khusus filter.*\n";
        $c.= "untuk memvalidasi parameter yang diterima. Selain bisa terlewatkan,\n";
        $c.= "akan membuat script semakin besar dengan hal2 yang seharusnya ditangani oleh framework itu sendiri.\n\n";
        $c.= "Dengan fitur annotation, kemungkinan method dieksekusi dengan parameter yang tidak diinginkan adalah <b>0%</b>.\n";
        $c.= "</pre>";

        return $c;
    }
}
?>